#include<iostream>

using namespace std;

int gcd(long long a,long long b)
{
	return b==0?a:gcd(b,a%b);
}
int main()
{
	string s;cin>>s;
	long long b;cin>>b;
	long long a=0;
	for(int i=0;i<s.size();i++)
	{
		a=a*10+(s[i]-'0');
		a%=b;
	}

	cout<<gcd(b,a)<<endl;
}